﻿using System;
using System.Collections.Generic;
using EmailJabber.EmailJabber.Core.Commands.Common;
using EmailJabber.Logic.Commands.Base;
using EmailJabber.Logic.Logic.BusinessLogic;

namespace EmailJabber.Logic.Commands
{
	public class HelpCommand:CommandBase
	{

		protected override string GetDecription()
		{
			return "Show this text;  Params 'l' - show full information; 'id' - show only ids";
		}

		protected override Guid GetId()
		{
			return new Guid("1B940A35-0C74-4D7C-8C9C-6E4CAE038F18");
		}

		protected override void ExecuteSafe(MessageIM comnd)
		{
			
			string messBody = "All commands:" + Environment.NewLine;
			foreach (KeyValuePair<List<string>, Guid> pair in BL.Instance.BotCommands)
			{
				CommandBase currentCommand = CommandManager.Instance.GetCommand(pair.Value);
				string aliases=string.Empty;
				foreach (string key in pair.Key)
				{
					aliases += key + "; ";
				}
				if(comnd.Body.Contains("id"))
				{
					messBody +=string.Format("{0}     : {1}", currentCommand.Id, currentCommand.Description)+Environment.NewLine;
					
				}
				else if(comnd.Body.Contains("l"))
				{
					messBody +=string.Format("{0}     : {1}      GUID: {2}", aliases, currentCommand.Description,currentCommand.Id)+Environment.NewLine;
				}				
				else
				{
					messBody +=string.Format("{0}     : {1}", aliases, currentCommand.Description)+Environment.NewLine;
				}				
			}
			MessageIM mess = new MessageIM(comnd.To,messBody,comnd.From);
			BL.Instance.Send(mess);
		}
	}
}